<?php /** @var BootActiveForm $form */
    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'workflow',
    'type'=>'search',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>

<div class="box">
<?php echo $form->textFieldRow($model, 'workflow_name', array('class'=>'input-large', 'prepend'=>'<i class="icon-search"></i>')); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'搜索')); ?>
</div>

<script>
function reloadGrid(data) {
    $.fn.yiiGridView.update('workflow-grid');
}

function checkSelect() {                                                  
    if($.fn.yiiGridView.getSelection("workflow-grid") == "") {
        alert('请选择至少一条记录');                                                    
        return false;                                                  
    }
    else {
        return true;
    }
}
</script>
<div class="btn-toolbar">

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'danger',
    'buttonType'=>'ajaxSubmit',
    'size'=>'small',
    'icon'=>'remove white',
    'label'=>'删除', 
    'url'=>array('workflow/ajaxDelete'), 
    'ajaxOptions'=>array(
		'beforeSend'=>  'checkSelect',
        'success'   =>  'reloadGrid',
    ),
    'htmlOptions'=>array(
        'confirm'=>'确认要删除吗?',
    ),

)); ?>

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'label'=>'新建工作流',
    'icon'=>'plus white',
    'url'=>array('workflow/create', 'type' => $_GET['type']),
    'size'=>'small',

)); ?>
</div>
<?php $this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'workflow-grid',
    'type'=>'striped bordered condensed',
    'dataProvider'  =>  $dataProvider,
    'pager'=>array(
        'class'=>'CLinkPager',           
        'nextPageLabel'=>'下一页>',           
        'prevPageLabel'=>'<上一页',           
        'header'=>'',   
    ),   
    'selectableRows'=> 2,
    'summaryText'   =>  '显示{start}-{end}条.共{count}条记录,当前第{page}页',
    'template'      =>  '{items}{pager}',
    'columns'       =>  array(
       array(
            'id'    =>  'autoId',
            'class' =>  'CCheckBoxColumn',
        ),
        array(
            'header'=>  '#',
            'name'  =>  'workflow_id',
            'value' =>  '$data["workflow_id"]'
        ),
       array(
            'header'=>  '工作流名',
            'name'  =>  'workflow_name',
			'type'  =>  'raw',
        	'value' =>  'CHtml::link(CHtml::encode($data["workflow_name"]), Yii::app()->controller->createUrl("workflow/update", array("id"=>$data["workflow_id"])))'
        ),
        array(
            'header'=>  '创建时间',
            'name'  =>  'workflow_created',
            'value' =>  'date("Y-m-d H:i:s", $data["workflow_created"])',
        ),
        array(
            'header'=>  '版本',
            'name'  =>  'workflow_version',
            'value' =>  '$data["workflow_version"]'
        ), 
        array(
            'class' =>  'bootstrap.widgets.TbButtonColumn',
            'htmlOptions'=>array('style'=>'width: 80px'),
            'template'=>'{graph}',           
            'buttons'=>array(
                 'graph'  =>  array(
                     'label'    =>  '查看图象',
                     'url'      =>  'Yii::app()->controller->createUrl("workflow/graph", array("id"=>$data["workflow_id"]))',
                     ),
                ),
        ),
        array(
            'class' =>  'bootstrap.widgets.TbButtonColumn',
             'template'=>'{view} {delete}',           
             'buttons'=>array(
                 'view'  =>  array(
                     'label'    =>  '查看结点列表',
                     'url'      =>  'Yii::app()->controller->createUrl("workflow/node", array("id"=>$data["workflow_id"]))',
                     ),
                'delete'   =>  array(
                    'label'     =>  '删除工作流',
                     'url'      =>  'Yii::app()->controller->createUrl("workflow/delete", array("id"=>$data["workflow_name"]))',
                    ),
                ),
        ),
    ),
));
?>
<?php $this->endWidget(); ?>
